package com.ingesup.caribou.client.gui.app;

import java.awt.Dimension;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JList;

import java.awt.BorderLayout;

import javax.swing.ButtonGroup;
import javax.swing.JDialog;
import javax.swing.JRadioButton;
import javax.swing.ListSelectionModel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSeparator;

import java.awt.GridLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

public class Caribou {

	private JFrame frmCaribouProject;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Caribou window = new Caribou();
					window.frmCaribouProject.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Caribou() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmCaribouProject = new JFrame();
		frmCaribouProject.setTitle("Caribou Project");
		frmCaribouProject.setBounds(100, 100, 800, 575);
		frmCaribouProject.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JList list = new JList();
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		list.setPreferredSize(new Dimension(170,frmCaribouProject.getHeight()));
		frmCaribouProject.getContentPane().add(list, BorderLayout.WEST);
		
		JPanel panel = new JPanel();
		frmCaribouProject.getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(new BorderLayout());
		
		JPanel radioButtons = new JPanel(new GridLayout(1,2));
		JRadioButton meridian = new JRadioButton("Meridien");
		JRadioButton parallel = new JRadioButton("Parallele");
		ButtonGroup buttonsGroup = new ButtonGroup();
		buttonsGroup.add(meridian);
		buttonsGroup.add(parallel);
		
		radioButtons.add(meridian);
		radioButtons.add(parallel);
		panel.add(radioButtons, BorderLayout.NORTH);
		
		JPanel pan_graphique = new JPanel();
		panel.add(pan_graphique, BorderLayout.CENTER);
		
		
		JMenuBar menuBar = new JMenuBar();
		frmCaribouProject.setJMenuBar(menuBar);
		frmCaribouProject.addWindowListener(new WindowListener() {
			
			@Override
			public void windowOpened(WindowEvent arg0) {
			}
			
			@Override
			public void windowIconified(WindowEvent arg0) {
			}
			
			@Override
			public void windowDeiconified(WindowEvent arg0) {
			}
			
			@Override
			public void windowDeactivated(WindowEvent arg0) {
			}
			
			@Override
			public void windowClosing(WindowEvent arg0) {
				System.exit(0);
			}
			
			@Override
			public void windowClosed(WindowEvent arg0) {
			}
			
			@Override
			public void windowActivated(WindowEvent arg0) {				
			}
		});
		
		JMenu mnFichier = new JMenu("Fichier");
		menuBar.add(mnFichier);
		
		JMenuItem mntmConnexion = new JMenuItem("Connexion ...");
		mntmConnexion.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					FrameConnection dialog = new FrameConnection(frmCaribouProject);
					dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
					dialog.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
		
		mnFichier.add(mntmConnexion);
		
		JMenuItem mntmDconnexion = new JMenuItem("D\u00E9connexion");
		mnFichier.add(mntmDconnexion);
		
		JSeparator separator_1 = new JSeparator();
		mnFichier.add(separator_1);
		
		JMenuItem mntmQuitter = new JMenuItem("Quitter");
		mntmQuitter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				System.exit(0);
			}
		});
		mnFichier.add(mntmQuitter);
		
		JMenu mnDonnes = new JMenu("Donn\u00E9es");
		menuBar.add(mnDonnes);
		
		JMenuItem mntmVisualiser = new JMenuItem("Visualiser ...");
		mnDonnes.add(mntmVisualiser);
		
		JSeparator separator = new JSeparator();
		mnDonnes.add(separator);
		
		JMenuItem mntmImporter = new JMenuItem("Importer ...");
		mnDonnes.add(mntmImporter);
		
		JMenuItem mntmExporter_1 = new JMenuItem("Exporter ...");
		mnDonnes.add(mntmExporter_1);
		
		JMenu menu = new JMenu("?");
		menuBar.add(menu);
		
		JMenuItem mntmAPropos = new JMenuItem("A propos");
		mntmAPropos.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					About dialog = new About(frmCaribouProject);
					dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
					dialog.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
		menu.add(mntmAPropos);
						
		JMenuItem mntmAide = new JMenuItem("Aide");
		mntmAide.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				try {
					Help dialog = new Help(frmCaribouProject);
					dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
					dialog.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
		menu.add(mntmAide);
	}

}
